/*
==============================================================================
 This is an automatically generated file created by the Jucer!
 Creation date:  26 May 2007 4:17:45 am
	Author: Prashant Vaibhav
 ------------------------------------------------------------------------------

 The Jucer is part of the JUCE library - "Jules' Utility Class Extensions"
 Copyright 2004-6 by Raw Material Software ltd.

 ==============================================================================
 */

//[Headers] You can add your own extra header files here...
//[/Headers]

#include "VmkDisplay.h"



//==============================================================================
VmkDisplay::VmkDisplay ()
    : Component (T("Virtual Midi Keyboard")),
      m_slPitchBend (0),
      m_Keyboard (0),
      m_cmbChannel (0),
      m_lbChannel (0),
      m_slVelocity (0),
      m_grControllers (0),
      m_btnTranspose (0),
      m_slTranspose (0),
      m_slController (0),
      m_lbController (0),
      m_slController2 (0),
      m_slController3 (0),
      m_slController4 (0),
      m_slController5 (0),
      m_slController6 (0),
      m_slController7 (0),
      m_slController8 (0),
      m_slController9 (0),
      m_lbController2 (0),
      m_lbController3 (0),
      m_lbController4 (0),
      m_lbController5 (0),
      m_lbController6 (0),
      m_lbController7 (0),
      m_lbController8 (0),
      m_lbController9 (0),
      m_slModWheel (0),
      m_slBendRange (0)
{
		//[Constructor] You can add your own custom stuff here..
		DBG("Opening the default MIDI port");
		m_MidiOut = MidiOutput::openDevice(MidiOutput::getDefaultDeviceIndex());
		DBG("Opened the MIDI device");
		
		m_KeyboardState = new MidiKeyboardState();
		m_KeyboardState->addListener(this); // this class will respond to any keypresses
		m_Keyboard = new MidiKeyboardComponent(*m_KeyboardState, MidiKeyboardComponent::horizontalKeyboard);
		//[/Constructor]
				
    addAndMakeVisible (m_slPitchBend = new Slider (T("Pitch Bend")));
    m_slPitchBend->setTooltip (T("Pitch bender"));
    m_slPitchBend->setRange (-63, 64, 1);
    m_slPitchBend->setSliderStyle (Slider::LinearHorizontal);
    m_slPitchBend->setTextBoxStyle (Slider::NoTextBox, false, 80, 20);
    m_slPitchBend->setColour (Slider::thumbColourId, Colour (0xffd77f00));
    m_slPitchBend->setColour (Slider::trackColourId, Colour (0x7f7e7e7e));
    m_slPitchBend->addListener (this);
		m_slPitchBend->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_Keyboard);
    m_Keyboard->setName (T("Midi Keyboard Display"));

    addAndMakeVisible (m_cmbChannel = new ComboBox (T("Output Channel")));
    m_cmbChannel->setTooltip (T("MIDI output channel number"));
    m_cmbChannel->setEditableText (false);
    m_cmbChannel->setJustificationType (Justification::centred);
    m_cmbChannel->setTextWhenNothingSelected (T("1"));
    m_cmbChannel->setTextWhenNoChoicesAvailable (T("-"));
    m_cmbChannel->addItem (T("1"), 1);
    m_cmbChannel->addItem (T("2"), 2);
    m_cmbChannel->addItem (T("3"), 3);
    m_cmbChannel->addItem (T("4"), 4);
    m_cmbChannel->addItem (T("5"), 5);
    m_cmbChannel->addItem (T("6"), 6);
    m_cmbChannel->addItem (T("7"), 7);
    m_cmbChannel->addItem (T("8"), 8);
    m_cmbChannel->addItem (T("9"), 9);
    m_cmbChannel->addItem (T("10"), 10);
    m_cmbChannel->addItem (T("11"), 11);
    m_cmbChannel->addItem (T("12"), 12);
    m_cmbChannel->addItem (T("13"), 13);
    m_cmbChannel->addItem (T("14"), 14);
    m_cmbChannel->addItem (T("15"), 15);
    m_cmbChannel->addItem (T("16"), 16);
    m_cmbChannel->addListener (this);
		m_cmbChannel->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_lbChannel = new Label (T("Channel"),
                                                T("midi ch")));
    m_lbChannel->setFont (Font (15.0000f, Font::plain));
    m_lbChannel->setJustificationType (Justification::centredRight);
    m_lbChannel->setEditable (false, false, false);
    m_lbChannel->setColour (Label::textColourId, Colours::white);
    m_lbChannel->setColour (TextEditor::textColourId, Colours::black);
    m_lbChannel->setColour (TextEditor::backgroundColourId, Colour (0x0));
		m_lbChannel->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slVelocity = new Slider (T("Velocity slider")));
    m_slVelocity->setTooltip (T("The velocity range of output notes"));
    m_slVelocity->setRange (0, 127, 1);
		m_slVelocity->setValue(100);
    m_slVelocity->setSliderStyle (Slider::LinearHorizontal);
    m_slVelocity->setTextBoxStyle (Slider::TextBoxRight, false, 35, 20);
    m_slVelocity->setColour (Slider::thumbColourId, Colour (0xffeeeeee));
    m_slVelocity->setColour (Slider::trackColourId, Colour (0x66777777));
    m_slVelocity->setColour (Slider::textBoxTextColourId, Colours::white);
    m_slVelocity->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slVelocity->setColour (Slider::textBoxHighlightColourId, Colour (0x4061a2ff));
    m_slVelocity->addListener (this);
		m_slVelocity->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_grControllers = new GroupComponent (T("Common Controllers"),
                                                             T("controllers")));
    m_grControllers->setTextLabelPosition (Justification::centredRight);
    m_grControllers->setColour (GroupComponent::outlineColourId, Colour (0x66ffffff));
    m_grControllers->setColour (GroupComponent::textColourId, Colours::white);
		m_grControllers->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_btnTranspose = new ToggleButton (T("Transpose")));
    m_btnTranspose->setTooltip (T("Switch note transpose on/off"));
    m_btnTranspose->setButtonText (T("transpose"));
    m_btnTranspose->addButtonListener (this);
    m_btnTranspose->setColour (ToggleButton::textColourId, Colours::white);
		m_btnTranspose->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slTranspose = new Slider (T("Transpose")));
    m_slTranspose->setTooltip (T("Number of semitones to transpose"));
    m_slTranspose->setRange (-48, 48, 1);
    m_slTranspose->setSliderStyle (Slider::IncDecButtons);
    m_slTranspose->setTextBoxStyle (Slider::TextBoxLeft, false, 35, 20);
    m_slTranspose->setColour (Slider::thumbColourId, Colour (0xffbfbfbf));
    m_slTranspose->setColour (Slider::textBoxTextColourId, Colours::white);
    m_slTranspose->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slTranspose->setColour (Slider::textBoxOutlineColourId, Colour (0x36ffffff));
    m_slTranspose->addListener (this);
		m_slTranspose->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slController = new Slider (T("Controller knob")));
    m_slController->setTooltip (T("Volume"));
    m_slController->setRange (-127, 0, 1);
    m_slController->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController->setTextBoxStyle (Slider::NoTextBox, false, 35, 15);
    m_slController->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController->addListener (this);
		m_slController->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_lbController = new Label (T("Controller name"),
                                                   T("volume")));
    m_lbController->setFont (Font (Font::getDefaultSansSerifFontName(), 12.9000f, Font::plain));
    m_lbController->setJustificationType (Justification::centred);
    m_lbController->setEditable (false, false, false);
    m_lbController->setColour (Label::textColourId, Colours::white);
    m_lbController->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController->setColour (TextEditor::textColourId, Colours::black);
    m_lbController->setColour (TextEditor::backgroundColourId, Colour (0x0));
		m_lbController->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slController2 = new Slider (T("Controller knob")));
    m_slController2->setTooltip (T("Panning"));
    m_slController2->setRange (-63, 64, 1);
    m_slController2->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController2->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController2->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController2->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController2->addListener (this);
		m_slController2->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slController3 = new Slider (T("Controller knob")));
    m_slController3->setTooltip (T("Expression"));
    m_slController3->setRange (-127, 0, 1);
    m_slController3->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController3->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController3->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController3->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController3->addListener (this);
		m_slController3->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slController4 = new Slider (T("Controller knob")));
    m_slController4->setTooltip (T("Filter cutoff frequency"));
    m_slController4->setRange (-63, 64, 1);
    m_slController4->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController4->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController4->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController4->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController4->addListener (this);
		m_slController4->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slController5 = new Slider (T("Controller knob")));
    m_slController5->setTooltip (T("Filter cutoff resonance (Q-factor)"));
    m_slController5->setRange (-63, 64, 1);
    m_slController5->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController5->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController5->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController5->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController5->addListener (this);
		m_slController5->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slController6 = new Slider (T("Controller knob")));
    m_slController6->setTooltip (T("Envelope Attack"));
    m_slController6->setRange (-63, 64, 1);
    m_slController6->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController6->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController6->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController6->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController6->addListener (this);
		m_slController6->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slController7 = new Slider (T("Controller knob")));
    m_slController7->setTooltip (T("Envelope Decay"));
    m_slController7->setRange (-63, 64, 1);
    m_slController7->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController7->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController7->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController7->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController7->addListener (this);
		m_slController7->setMouseClickGrabsKeyboardFocus(false);
		
    addAndMakeVisible (m_slController8 = new Slider (T("Controller knob")));
    m_slController8->setTooltip (T("Envelope Sustain"));
    m_slController8->setRange (-63, 64, 1);
    m_slController8->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController8->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController8->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController8->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController8->addListener (this);
		m_slController8->setMouseClickGrabsKeyboardFocus(false);
		
    addAndMakeVisible (m_slController9 = new Slider (T("Controller knob")));
    m_slController9->setTooltip (T("Envelope Release"));
    m_slController9->setRange (-63, 64, 1);
    m_slController9->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slController9->setTextBoxStyle (Slider::TextBoxAbove, false, 35, 15);
    m_slController9->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slController9->setColour (Slider::textBoxOutlineColourId, Colour (0x808080));
    m_slController9->addListener (this);
		m_slController9->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_lbController2 = new Label (T("Controller name"),
                                                    T("pan")));
    m_lbController2->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController2->setJustificationType (Justification::centred);
    m_lbController2->setEditable (false, false, false);
    m_lbController2->setColour (Label::textColourId, Colours::white);
    m_lbController2->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController2->setColour (TextEditor::textColourId, Colours::black);
    m_lbController2->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_lbController3 = new Label (T("Controller name"),
                                                    T("expr")));
    m_lbController3->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController3->setJustificationType (Justification::centred);
    m_lbController3->setEditable (false, false, false);
    m_lbController3->setColour (Label::textColourId, Colours::white);
    m_lbController3->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController3->setColour (TextEditor::textColourId, Colours::black);
    m_lbController3->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_lbController4 = new Label (T("Controller name"),
                                                    T("cutoff")));
    m_lbController4->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController4->setJustificationType (Justification::centred);
    m_lbController4->setEditable (false, false, false);
    m_lbController4->setColour (Label::textColourId, Colours::white);
    m_lbController4->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController4->setColour (TextEditor::textColourId, Colours::black);
    m_lbController4->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_lbController5 = new Label (T("Controller name"),
                                                    T("reso")));
    m_lbController5->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController5->setJustificationType (Justification::centred);
    m_lbController5->setEditable (false, false, false);
    m_lbController5->setColour (Label::textColourId, Colours::white);
    m_lbController5->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController5->setColour (TextEditor::textColourId, Colours::black);
    m_lbController5->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_lbController6 = new Label (T("Controller name"),
                                                    T("A")));
    m_lbController6->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController6->setJustificationType (Justification::centred);
    m_lbController6->setEditable (false, false, false);
    m_lbController6->setColour (Label::textColourId, Colours::white);
    m_lbController6->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController6->setColour (TextEditor::textColourId, Colours::black);
    m_lbController6->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_lbController7 = new Label (T("Controller name"),
                                                    T("D")));
    m_lbController7->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController7->setJustificationType (Justification::centred);
    m_lbController7->setEditable (false, false, false);
    m_lbController7->setColour (Label::textColourId, Colours::white);
    m_lbController7->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController7->setColour (TextEditor::textColourId, Colours::black);
    m_lbController7->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_lbController8 = new Label (T("Controller name"),
                                                    T("S")));
    m_lbController8->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController8->setJustificationType (Justification::centred);
    m_lbController8->setEditable (false, false, false);
    m_lbController8->setColour (Label::textColourId, Colours::white);
    m_lbController8->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController8->setColour (TextEditor::textColourId, Colours::black);
    m_lbController8->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_lbController9 = new Label (T("Controller name"),
                                                    T("R")));
    m_lbController9->setFont (Font (Font::getDefaultSansSerifFontName(), 11.0000f, Font::plain));
    m_lbController9->setJustificationType (Justification::centred);
    m_lbController9->setEditable (false, false, false);
    m_lbController9->setColour (Label::textColourId, Colours::white);
    m_lbController9->setColour (Label::outlineColourId, Colour (0x0));
    m_lbController9->setColour (TextEditor::textColourId, Colours::black);
    m_lbController9->setColour (TextEditor::backgroundColourId, Colour (0x0));

    addAndMakeVisible (m_slModWheel = new Slider (T("Modulation")));
    m_slModWheel->setTooltip (T("Modulation wheel"));
    m_slModWheel->setRange (0, 127, 1);
    m_slModWheel->setSliderStyle (Slider::RotaryVerticalDrag);
    m_slModWheel->setTextBoxStyle (Slider::NoTextBox, false, 80, 20);
    m_slModWheel->addListener (this);
		m_slModWheel->setMouseClickGrabsKeyboardFocus(false);

    addAndMakeVisible (m_slBendRange = new Slider (T("Pitch Bend Range")));
    m_slBendRange->setTooltip (T("Pitch bend range in semitones"));
    m_slBendRange->setRange (-24, 24, 1);
    m_slBendRange->setSliderStyle (Slider::IncDecButtons);
    m_slBendRange->setTextBoxStyle (Slider::TextBoxLeft, false, 30, 20);
    m_slBendRange->setColour (Slider::thumbColourId, Colour (0xffbfbfbf));
    m_slBendRange->setColour (Slider::textBoxTextColourId, Colours::white);
    m_slBendRange->setColour (Slider::textBoxBackgroundColourId, Colour (0x27ffffff));
    m_slBendRange->setColour (Slider::textBoxOutlineColourId, Colour (0x36ffffff));
    m_slBendRange->addListener (this);
		m_slBendRange->setMouseClickGrabsKeyboardFocus(false);

    setSize (696, 200);
}

VmkDisplay::~VmkDisplay()
{
    //[Destructor_pre]. You can add your own custom destruction code here..
    //[/Destructor_pre]

    deleteAndZero (m_slPitchBend);
    deleteAndZero (m_Keyboard);
    deleteAndZero (m_cmbChannel);
    deleteAndZero (m_lbChannel);
    deleteAndZero (m_slVelocity);
    deleteAndZero (m_grControllers);
    deleteAndZero (m_btnTranspose);
    deleteAndZero (m_slTranspose);
    deleteAndZero (m_slController);
    deleteAndZero (m_lbController);
    deleteAndZero (m_slController2);
    deleteAndZero (m_slController3);
    deleteAndZero (m_slController4);
    deleteAndZero (m_slController5);
    deleteAndZero (m_slController6);
    deleteAndZero (m_slController7);
    deleteAndZero (m_slController8);
    deleteAndZero (m_slController9);
    deleteAndZero (m_lbController2);
    deleteAndZero (m_lbController3);
    deleteAndZero (m_lbController4);
    deleteAndZero (m_lbController5);
    deleteAndZero (m_lbController6);
    deleteAndZero (m_lbController7);
    deleteAndZero (m_lbController8);
    deleteAndZero (m_lbController9);
    deleteAndZero (m_slModWheel);
    deleteAndZero (m_slBendRange);

    //[Destructor]. You can add your own custom destruction code here..
    //[/Destructor]
}

//==============================================================================
void VmkDisplay::paint (Graphics& g)
{
    g.fillAll (Colour (0xff8796af));

    //[UserPaint] Add your own custom paint stuff here..
    //[/UserPaint]
}

void VmkDisplay::resized()
{
    m_slPitchBend->setBounds (8, 56, 192, 24);
    m_Keyboard->setBounds ((getWidth() / 2) - ((696) / 2), getHeight() - 112, 696, 112);
    m_cmbChannel->setBounds (72, 8, 40, 20);
    m_lbChannel->setBounds (8, 8, 56, 24);
    m_slVelocity->setBounds (8, 32, 296, 24);
    m_grControllers->setBounds (304, 0, getWidth() - 304, 88);
    m_btnTranspose->setBounds (120, 8, 88, 24);
    m_slTranspose->setBounds (208, 8, 96, 24);
    m_slController->setBounds (632, 16, 56, 56);
    m_lbController->setBounds (632, 72, 56, 8);
    m_slController2->setBounds (312, 16, 40, 56);
    m_slController3->setBounds (352, 16, 40, 56);
    m_slController4->setBounds (392, 16, 40, 56);
    m_slController5->setBounds (432, 16, 40, 56);
    m_slController6->setBounds (472, 16, 40, 56);
    m_slController7->setBounds (512, 16, 40, 56);
    m_slController8->setBounds (552, 16, 40, 56);
    m_slController9->setBounds (592, 16, 40, 56);
    m_lbController2->setBounds (312, 72, 40, 8);
    m_lbController3->setBounds (352, 72, 40, 8);
    m_lbController4->setBounds (392, 72, 40, 8);
    m_lbController5->setBounds (432, 72, 40, 8);
    m_lbController6->setBounds (472, 72, 40, 8);
    m_lbController7->setBounds (512, 72, 40, 8);
    m_lbController8->setBounds (552, 72, 40, 8);
    m_lbController9->setBounds (592, 72, 40, 8);
    m_slModWheel->setBounds (272, 48, 32, 40);
    m_slBendRange->setBounds (200, 56, 72, 24);
    //[UserResized] Add your own custom resize handling here..
    //[/UserResized]
}

void VmkDisplay::sliderValueChanged (Slider* sliderThatWasMoved)
{
    //[UsersliderValueChanged_Pre]
    //[/UsersliderValueChanged_Pre]

    if (sliderThatWasMoved == m_slPitchBend)
    {
        //[UserSliderCode_m_slPitchBend] -- add your slider handling code here..
        //[/UserSliderCode_m_slPitchBend]
    }
    else if (sliderThatWasMoved == m_slVelocity)
    {
        //[UserSliderCode_m_slVelocity] -- add your slider handling code here..
				m_Keyboard->setVelocity((float) m_slVelocity->getValue()/127.0 );
        //[/UserSliderCode_m_slVelocity]
    }
    else if (sliderThatWasMoved == m_slTranspose)
    {
        //[UserSliderCode_m_slTranspose] -- add your slider handling code here..
        //[/UserSliderCode_m_slTranspose]
    }
    else if (sliderThatWasMoved == m_slController)
    {
        //[UserSliderCode_m_slController] -- add your slider handling code here..
        //[/UserSliderCode_m_slController]
    }
    else if (sliderThatWasMoved == m_slController2)
    {
        //[UserSliderCode_m_slController2] -- add your slider handling code here..
        //[/UserSliderCode_m_slController2]
    }
    else if (sliderThatWasMoved == m_slController3)
    {
        //[UserSliderCode_m_slController3] -- add your slider handling code here..
        //[/UserSliderCode_m_slController3]
    }
    else if (sliderThatWasMoved == m_slController4)
    {
        //[UserSliderCode_m_slController4] -- add your slider handling code here..
        //[/UserSliderCode_m_slController4]
    }
    else if (sliderThatWasMoved == m_slController5)
    {
        //[UserSliderCode_m_slController5] -- add your slider handling code here..
        //[/UserSliderCode_m_slController5]
    }
    else if (sliderThatWasMoved == m_slController6)
    {
        //[UserSliderCode_m_slController6] -- add your slider handling code here..
        //[/UserSliderCode_m_slController6]
    }
    else if (sliderThatWasMoved == m_slController7)
    {
        //[UserSliderCode_m_slController7] -- add your slider handling code here..
        //[/UserSliderCode_m_slController7]
    }
    else if (sliderThatWasMoved == m_slController8)
    {
        //[UserSliderCode_m_slController8] -- add your slider handling code here..
        //[/UserSliderCode_m_slController8]
    }
    else if (sliderThatWasMoved == m_slController9)
    {
        //[UserSliderCode_m_slController9] -- add your slider handling code here..
        //[/UserSliderCode_m_slController9]
    }
    else if (sliderThatWasMoved == m_slModWheel)
    {
        //[UserSliderCode_m_slModWheel] -- add your slider handling code here..
        //[/UserSliderCode_m_slModWheel]
    }
    else if (sliderThatWasMoved == m_slBendRange)
    {
        //[UserSliderCode_m_slBendRange] -- add your slider handling code here..
        //[/UserSliderCode_m_slBendRange]
    }

    //[UsersliderValueChanged_Post]
    //[/UsersliderValueChanged_Post]
}

void VmkDisplay::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
{
    //[UsercomboBoxChanged_Pre]
    //[/UsercomboBoxChanged_Pre]

    if (comboBoxThatHasChanged == m_cmbChannel)
    {
        //[UserComboBoxCode_m_cmbChannel] -- add your combo box handling code here..
			m_Keyboard->setMidiChannel(m_cmbChannel->getSelectedItemIndex()-1);
        //[/UserComboBoxCode_m_cmbChannel]
    }

    //[UsercomboBoxChanged_Post]
    //[/UsercomboBoxChanged_Post]
}

void VmkDisplay::buttonClicked (Button* buttonThatWasClicked)
{
    //[UserbuttonClicked_Pre]
    //[/UserbuttonClicked_Pre]

    if (buttonThatWasClicked == m_btnTranspose)
    {
        //[UserButtonCode_m_btnTranspose] -- add your button handler code here..
        //[/UserButtonCode_m_btnTranspose]
    }

    //[UserbuttonClicked_Post]
    //[/UserbuttonClicked_Post]
}

void VmkDisplay::keyPressed (const KeyPress& key)
{
    //[UserCode_keyPressed] -- Add your code here...
    //[/UserCode_keyPressed]
}



//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
void VmkDisplay::handleNoteOn(MidiKeyboardState* source, int midiChannel, int midiNote, float vel) {
	DBG("Passing midi note ON  ch " + String(midiChannel) + " note " + String(midiNote) + " vel " + String(vel));
	if (m_btnTranspose->getToggleState()) midiNote += (int) m_slTranspose->getValue();
	m_MidiOut->sendMessageNow(MidiMessage::noteOn(midiChannel, midiNote, vel));
}

void VmkDisplay::handleNoteOff(MidiKeyboardState* source, int midiChannel, int midiNote) {
	DBG("Passing midi note OFF ch " + String(midiChannel) + " note " + String(midiNote));
	if (m_btnTranspose->getToggleState()) midiNote += (int) m_slTranspose->getValue();
	m_MidiOut->sendMessageNow(MidiMessage::noteOff(midiChannel, midiNote));
}
//[/MiscUserCode]


//==============================================================================
#if 0
/*  -- Jucer information section --

    This is where the Jucer puts all of its metadata, so don't change anything in here!

BEGIN_JUCER_METADATA

<JUCER_COMPONENT documentType="Component" className="VmkDisplay" componentName="Virtual Midi Keyboard"
                 parentClasses="public Component, public MidiKeyboardStateListener"
                 constructorParams="" variableInitialisers="" snapPixels="8" snapActive="1"
                 snapShown="1" overlayOpacity="0.330000013" fixedSize="1" initialWidth="696"
                 initialHeight="200">
  <METHODS>
    <METHOD name="keyPressed (const KeyPress&amp; key)"/>
  </METHODS>
  <BACKGROUND backgroundColour="ff8796af"/>
  <SLIDER name="Pitch Bend" id="4eb58391be3c3aa4" memberName="m_slPitchBend"
          virtualName="" pos="8 56 192 24" tooltip="Pitch bender" thumbcol="ffd77f00"
          trackcol="7f7e7e7e" min="-63" max="64" int="1" style="LinearHorizontal"
          textBoxPos="NoTextBox" textBoxEditable="1" textBoxWidth="80"
          textBoxHeight="20"/>
  <GENERICCOMPONENT name="Midi Keyboard Display" id="6684e95b7387450f" memberName="m_Keyboard"
                    virtualName="" pos="0Cc 0Rr 696 112" class="MidiKeyboardComponent"
                    params=""/>
  <COMBOBOX name="Output Channel" id="1979cabebb18c1ae" memberName="m_cmbChannel"
            virtualName="" pos="72 8 40 20" tooltip="MIDI output channel number"
            editable="0" layout="36" items="1&#10;2&#10;3&#10;4&#10;5&#10;6&#10;7&#10;8&#10;9&#10;10&#10;11&#10;12&#10;13&#10;14&#10;15&#10;16"
            textWhenNonSelected="1" textWhenNoItems="-"/>
  <LABEL name="Channel" id="5865d1247260d6f0" memberName="m_lbChannel"
         virtualName="" pos="8 8 56 24" textCol="ffffffff" edTextCol="ff000000"
         edBkgCol="0" labelText="midi ch" editableSingleClick="0" editableDoubleClick="0"
         focusDiscardsChanges="0" fontname="Default font" fontsize="15"
         bold="0" italic="0" justification="34"/>
  <SLIDER name="Velocity slider" id="cd148c8a7160d1b0" memberName="m_slVelocity"
          virtualName="" pos="8 32 296 24" tooltip="The velocity range of output notes"
          thumbcol="ffeeeeee" trackcol="66777777" textboxtext="ffffffff"
          textboxbkgd="27ffffff" textboxhighlight="4061a2ff" min="0" max="127"
          int="1" style="TwoValueHorizontal" textBoxPos="NoTextBox" textBoxEditable="1"
          textBoxWidth="35" textBoxHeight="20"/>
  <GROUPCOMPONENT name="Common Controllers" id="e568262b90faf2f4" memberName="m_grControllers"
                  virtualName="" pos="696r 0 304M 88" outlinecol="66ffffff" textcol="ffffffff"
                  title="controllers" textpos="34"/>
  <TOGGLEBUTTON name="Transpose" id="551a3faa58c0f160" memberName="m_btnTranspose"
                virtualName="" pos="120 8 88 24" tooltip="Switch note transpose on/off"
                txtcol="ffffffff" buttonText="transpose" connectedEdges="0" needsCallback="1"
                state="0"/>
  <SLIDER name="Transpose" id="a4bce73124a54ba6" memberName="m_slTranspose"
          virtualName="" pos="208 8 96 24" tooltip="Number of semitones to transpose"
          thumbcol="ffbfbfbf" textboxtext="ffffffff" textboxbkgd="27ffffff"
          textboxoutline="36ffffff" min="-48" max="48" int="1" style="IncDecButtons"
          textBoxPos="TextBoxLeft" textBoxEditable="1" textBoxWidth="35"
          textBoxHeight="20"/>
  <SLIDER name="Controller knob" id="5a9c70062c5bc5a2" memberName="m_slController"
          virtualName="" pos="632 16 56 56" tooltip="Volume" textboxbkgd="27ffffff"
          min="-127" max="0" int="1" style="RotaryVerticalDrag" textBoxPos="NoTextBox"
          textBoxEditable="1" textBoxWidth="35" textBoxHeight="15"/>
  <LABEL name="Controller name" id="84fa83bce3aba6c1" memberName="m_lbController"
         virtualName="" pos="632 72 56 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="volume" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="12.9" bold="0" italic="0" justification="36"/>
  <SLIDER name="Controller knob" id="81290e488fc0b85f" memberName="m_slController2"
          virtualName="" pos="312 16 40 56" tooltip="Panning" textboxbkgd="27ffffff"
          textboxoutline="808080" min="-63" max="64" int="1" style="RotaryVerticalDrag"
          textBoxPos="TextBoxAbove" textBoxEditable="1" textBoxWidth="35"
          textBoxHeight="15"/>
  <SLIDER name="Controller knob" id="c1c34631bc0e298a" memberName="m_slController3"
          virtualName="" pos="352 16 40 56" tooltip="Expression" textboxbkgd="27ffffff"
          textboxoutline="808080" min="-127" max="0" int="1" style="RotaryVerticalDrag"
          textBoxPos="TextBoxAbove" textBoxEditable="1" textBoxWidth="35"
          textBoxHeight="15"/>
  <SLIDER name="Controller knob" id="51f9efdafc33203b" memberName="m_slController4"
          virtualName="" pos="392 16 40 56" tooltip="Filter cutoff frequency"
          textboxbkgd="27ffffff" textboxoutline="808080" min="-63" max="64"
          int="1" style="RotaryVerticalDrag" textBoxPos="TextBoxAbove"
          textBoxEditable="1" textBoxWidth="35" textBoxHeight="15"/>
  <SLIDER name="Controller knob" id="100bea74a4eb80e1" memberName="m_slController5"
          virtualName="" pos="432 16 40 56" tooltip="Filter cutoff resonance (Q-factor)"
          textboxbkgd="27ffffff" textboxoutline="808080" min="-63" max="64"
          int="1" style="RotaryVerticalDrag" textBoxPos="TextBoxAbove"
          textBoxEditable="1" textBoxWidth="35" textBoxHeight="15"/>
  <SLIDER name="Controller knob" id="b52a0622993b4b4c" memberName="m_slController6"
          virtualName="" pos="472 16 40 56" tooltip="Envelope Attack" textboxbkgd="27ffffff"
          textboxoutline="808080" min="-63" max="64" int="1" style="RotaryVerticalDrag"
          textBoxPos="TextBoxAbove" textBoxEditable="1" textBoxWidth="35"
          textBoxHeight="15"/>
  <SLIDER name="Controller knob" id="f1dd8894b455a936" memberName="m_slController7"
          virtualName="" pos="512 16 40 56" tooltip="Envelope Decay" textboxbkgd="27ffffff"
          textboxoutline="808080" min="-63" max="64" int="1" style="RotaryVerticalDrag"
          textBoxPos="TextBoxAbove" textBoxEditable="1" textBoxWidth="35"
          textBoxHeight="15"/>
  <SLIDER name="Controller knob" id="d49f2baa32fd3b8a" memberName="m_slController8"
          virtualName="" pos="552 16 40 56" tooltip="Envelope Sustain"
          textboxbkgd="27ffffff" textboxoutline="808080" min="-63" max="64"
          int="1" style="RotaryVerticalDrag" textBoxPos="TextBoxAbove"
          textBoxEditable="1" textBoxWidth="35" textBoxHeight="15"/>
  <SLIDER name="Controller knob" id="1d4dce24537e1892" memberName="m_slController9"
          virtualName="" pos="592 16 40 56" tooltip="Envelope Release"
          textboxbkgd="27ffffff" textboxoutline="808080" min="-63" max="64"
          int="1" style="RotaryVerticalDrag" textBoxPos="TextBoxAbove"
          textBoxEditable="1" textBoxWidth="35" textBoxHeight="15"/>
  <LABEL name="Controller name" id="2e620dc08f4b1b93" memberName="m_lbController2"
         virtualName="" pos="312 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="pan" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <LABEL name="Controller name" id="139ab7a074c03d8" memberName="m_lbController3"
         virtualName="" pos="352 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="expr" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <LABEL name="Controller name" id="fb357e740beda113" memberName="m_lbController4"
         virtualName="" pos="392 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="cutoff" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <LABEL name="Controller name" id="771a551220ceb111" memberName="m_lbController5"
         virtualName="" pos="432 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="reso" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <LABEL name="Controller name" id="c5226259e13fdcf1" memberName="m_lbController6"
         virtualName="" pos="472 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="A" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <LABEL name="Controller name" id="24c9a0a012e777c1" memberName="m_lbController7"
         virtualName="" pos="512 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="D" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <LABEL name="Controller name" id="d6f12b87a6900369" memberName="m_lbController8"
         virtualName="" pos="552 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="S" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <LABEL name="Controller name" id="5289c5283c5f9fc7" memberName="m_lbController9"
         virtualName="" pos="592 72 40 8" textCol="ffffffff" outlineCol="0"
         edTextCol="ff000000" edBkgCol="0" labelText="R" editableSingleClick="0"
         editableDoubleClick="0" focusDiscardsChanges="0" fontname="Default sans-serif font"
         fontsize="11" bold="0" italic="0" justification="36"/>
  <SLIDER name="Modulation" id="543a00b9dcc0777a" memberName="m_slModWheel"
          virtualName="" pos="272 48 32 40" tooltip="Modulation wheel"
          min="0" max="127" int="1" style="RotaryVerticalDrag" textBoxPos="NoTextBox"
          textBoxEditable="1" textBoxWidth="80" textBoxHeight="20"/>
  <SLIDER name="Pitch Bend Range" id="d63f24505dd3a3de" memberName="m_slBendRange"
          virtualName="" pos="200 56 72 24" tooltip="Pitch bend range in semitones"
          thumbcol="ffbfbfbf" textboxtext="ffffffff" textboxbkgd="27ffffff"
          textboxoutline="36ffffff" min="-24" max="24" int="1" style="IncDecButtons"
          textBoxPos="TextBoxLeft" textBoxEditable="1" textBoxWidth="30"
          textBoxHeight="20"/>
</JUCER_COMPONENT>

END_JUCER_METADATA
*/
#endif
